import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By


# 打开浏览器
driver = webdriver.Chrome()
# 最大化
# driver.maximize_window()
# 打开网页
driver.get("https://research.qmpsee.com/ranking")

time.sleep(2)

divs = driver.find_elements(By.XPATH,'//*[@id="app"]/section/main/div[1]/div[2]/div/div')
for div in divs:
    find = driver.find_element(By.XPATH,'.//button')
    # 点击查看详情
    find.click()
    time.sleep(6)

    # 获取所有窗口
    all_handles = driver.window_handles
    # 打开新窗口
    for handle in all_handles:
        if handle != driver.current_window_handle:
            driver.switch_to.window(handle)
    title = driver.find_element(By.XPATH,'//*[@id="app"]/div[2]/div[1]/div/div[1]').text
    print(title)
    time.sleep(2)

    # 操作完成后，可以选择切换回原窗口
    driver.switch_to.window(all_handles[0])
    break


# 退出浏览器
# driver.quit()